package com.lagou.edu.wwyan.web1.minicat;

/**
 * http协议工具类
 */
public class HttpProtocolUtil {

    /**
     * 相应请求头
     * @return
     */
    public static String getHttpHeader(int status,long contentLength) {
        return "HTTP/1.1 "+status+" OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + contentLength + " \n" +
                "\r\n";
    }

    /**
     * 封装相应信息
     * @return
     */
    public static String getHttpResultString(int status,String content) {
        content = content == null ? "" : content;
        return getHttpHeader(status,content.getBytes().length) + content;
    }  /**
     * 封装相应信息
     * @return
     */
    public static String getHttpResultString(String content) {
        return getHttpResultString(200,content);
    }

    /**
     * 为响应码404返回信息
     * @return
     */
    public static String getHttpResult404() {
        String str404 = "<h1>404 not found</h1>";
        return getHttpResultString(404,str404);
    }


}
